package com.x.xiaoshuo.ui.appbar;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.x.mvp.appbar.AppBarBuilder;
import com.x.xiaoshuo.R;


public class LeftTitleAppBarBuilder extends AppBarBuilder {
    ImageView icon;
    TextView txt;

    int res;
    String text;

    @Override
    protected View getCenterSpace(LayoutInflater layoutInflater) {
        return null;
    }

    @Override
    protected View getRightSpace(LayoutInflater layoutInflater) {
        return null;
    }

    @Override
    protected View getLeftSpace(LayoutInflater layoutInflater) {
        View left = layoutInflater.inflate(R.layout.toolbar_left_title, null);
        icon = (ImageView) left.findViewById(R.id.icon);
        txt = (TextView) left.findViewById(R.id.txt);
        if (res != 0) {
            icon.setImageResource(res);
        }
        if (!TextUtils.isEmpty(text)) {
            txt.setText(text);
        }
        return left;
    }

    public void setRes(int res) {
        this.res = res;
        if (icon != null) {
            icon.setImageResource(res);
        }
    }

    public void setText(String text) {
        this.text = text;
        if (txt != null) {
            txt.setText(text);
        }
    }
}
